import numpy as np
import json
import pickle
import sys

def test1():
    data = np.array([[1, 2, 3], [4, 5 ,6], [7 ,8, 9]])
    ans = np.linalg.eig(data)
    print(type(ans))
    print(ans)
    print(ans[0])
    print(ans[1])
    ans_zipped = [[a, b] for a, b in zip(ans[0], ans[1].T)]
    ans_zipped.sort(key=lambda x:x[0], reverse=True)
    print(ans_zipped)
    sorted_vec = [b for a, b in ans_zipped]
    print(sorted_vec)
    print(type(sorted_vec))
    print()
    arr = np.array(sorted_vec).T
    ans = [vec[:2] for vec in arr]
    ans = np.array(ans)
    print(ans)
    return None

def test2():
    a = np.zeros(shape=[2, 2])
    b = np.array([[1, 2], [3, 4]])
    c = np.array([[5, 6], [7, 8]])
    a += b
    a += c
    a *= 4

    print(a)

def test3():
    arr1 = np.array([[1, 2, 3] ,[4, 5, 6]])
    arr2 = np.array([[1, 2], [3, 4], [5, 6]])
    print(arr1.shape)
    print(arr2.shape)
    arr = np.matmul(arr1, arr2)

    print(arr)
    arr = np.array([[1, 2], [3, 4]])

    distance = np.linalg.norm(arr)      #L2范数
    print(distance)

    return None


def test4():
    d = np.array([[1, 2], [3, 4], [5, 6]])
    s = pickle.dumps(d)
    print(s)
    print(type(s))
    with open('test.pickle', 'wb') as f:
        f.write(s)
    with open('test.pickle', 'rb') as f:
        s = f.read()
        d = pickle.loads(s)
        print(d)
        print(type(d))
    return 0;

def test5():
    with open('./W.pickle', 'rb') as f:
        data = pickle.load(f)
        print(data)
        print(type(data))
        print(data.shape)

def test6():
    argv = sys.argv
    print(argv)

test6()
